package com.fafa.File;

import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class Properties_ {
    public static void main(String[] args) throws IOException {


    }

    @Test
    public void read() throws IOException {
        Properties properties = new Properties();
        //加载配置文件
        properties.load(new FileReader("src\\com\\fafa\\File\\mysql.properties"));

        properties.list(System.out);
        System.out.println(properties.getProperty("user"));
    }

    @Test
    public void write() throws IOException {
        Properties properties = new Properties();
        //加进配置文件
        properties.setProperty("charset","utf-8");
        properties.setProperty("user","汤姆");
        properties.setProperty("pwd","root");
        //将k-v存储到文件中
        properties.store(new FileWriter("src\\com\\fafa\\File\\mysql2.properties"),null);

        System.out.println("保存配置文件成功");
    }
}
